using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Deepcode.Flux.Core.Data;

namespace Deepcode.Flux.Core.Systems.Registry
{
	/// <summary>
	/// Represents a single node within the Flux registry
	/// </summary>
	public class RegistryDataNode
	{
		#region Field properties
		private int _PK_ID = -1;
		private int _FK_ParentID = -1;
		private string _KeyName = "";
		private int _KeyType = (int) FluxRegistryKeyType.NODEPATH;
		private string _ValueString = "";
		#endregion
		#region Public properties to set/get field information
		/// <summary>
		/// Get/Set the PK_ID field from the record
		/// </summary>
		public int PK_ID { get { return _PK_ID; } set { _PK_ID = value; } }
		/// <summary>
		/// Get/Set the FK_ParentID field from the record
		/// </summary>
		public int FK_ParentID { get { return _FK_ParentID; } set { _FK_ParentID = value; } }
		/// <summary>
		/// Get/Set the KeyName field from the record
		/// </summary>
		public string KeyName { get { return _KeyName; } set { _KeyName = value; } }
		/// <summary>
		/// Get/Set the KeyType field from the record
		/// </summary>
		public int KeyType { get { return _KeyType; } set { _KeyType = value; } }
		/// <summary>
		/// Get/Set the ValueString field from the record
		/// </summary>
		public string ValueString { get { return _ValueString; } set { _ValueString = value; } }
		#endregion

		public RegistryDataNode [] Children
		{
			get
			{
				RegistryDataManager r = new RegistryDataManager();
				return r.GetChildrenFor(this.PK_ID);
			}
		}

		public RegistryDataNode Parent
		{
			get
			{
				RegistryDataManager r = new RegistryDataManager();
				return r.GetByID( this.FK_ParentID );
			}
		}

		public RegistryDataNode() { }
		public RegistryDataNode(DataRow r)
		{
			PK_ID = SQLUtility.DBNull(r["PK_ID"], -1);
			FK_ParentID = SQLUtility.DBNull(r["FK_ParentID"], -1);
			KeyName = SQLUtility.DBNull(r["KeyName"], "");
			KeyType = SQLUtility.DBNull(r["KeyType"], -1);
			ValueString = SQLUtility.DBNull(r["ValueString"], "");
		}
	}
}
